<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>6-1</title>
    <style>
        body {
            background-color: rgb(241, 237, 238);
        }
    </style>
</head>

<body>
    <input type="button" value="开关灯" id="light">
    <script>
        var light = document.getElementById('light');
        light.onclick = function() {
            var a = document.querySelector('body');
            // var a = document.getElementsByTagName('body');这个代替上述代码不可
            a.style.backgroundColor = 'black';

        }
    </script>
</body>

</html>